package com.blog.common.code;

import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;
public class ApplicationConstants {

	
	public static final String ENCODEING = "UTF-8";

    public static final String UPLOAD_PATH = "/upload/";

    public static final String GIF = ".gif";

    static Logger LOG = Logger.getLogger("applicatoin constatns");

    static Properties properties;

    static String fileMd5;

    public static String getValue(String key) {
        try {
            if (properties == null) {
                //如果配置文件在classpath目录下可以使用ClassPathResource对象
                Resource resource = new ClassPathResource("/conf.properties");
//                org.springframework.core.io.Resource resource = new FileSystemResource(configFile);
                properties = PropertiesLoaderUtils.loadProperties(resource);
            }
            //根URL
            return new String(properties.get(key).toString());

        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String baseUrl() {
        return getValue("base.url");
    }

    public static String staticPath() {
        return getValue("base.upload.path");
    }

    public static String staticUrl() {
        return getValue("base.static.url");
    }

    
    
}
